package com.ymatou.userservice.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.userservice.parameter.CheckMobileIsBindYmatouUserDtoBean;
import com.ymatou.userservice.service.CheckMobileIsBindYmatouUserDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.database.model.YmtMobilePhoneAccount;
import com.ymttest.database.sqlwapper.YmtMobilePhoneAccountWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;

/**
*检查手机是否注册过洋码头账号接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CheckMobileIsBindYmatouUserDto{
	private static CheckMobileIsBindYmatouUserDtoBean checkmobileisbindymatouuserdtoBean;
	private static CheckMobileIsBindYmatouUserDtoCall checkmobileisbindymatouuserdtoCall;
	private static YmtMobilePhoneAccountWapper mobilePhoneWapper;
	
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("检查手机是否注册过洋码头账号接口");
	}

	@Before
	public void caseUp() {
		checkmobileisbindymatouuserdtoBean=new CheckMobileIsBindYmatouUserDtoBean();
		checkmobileisbindymatouuserdtoCall=new CheckMobileIsBindYmatouUserDtoCall();
		mobilePhoneWapper = new YmtMobilePhoneAccountWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(checkmobileisbindymatouuserdtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckMobileIsBindYmatouUserDto_001() {
		Logger.start(true,"手机绑定过洋码头账号，验证绑定过");
		try {
			YmtMobilePhoneAccount user = mobilePhoneWapper.getAccountInfo();
			checkmobileisbindymatouuserdtoBean.setMobile(user.getSaccountname());
			checkmobileisbindymatouuserdtoCall.setData(checkmobileisbindymatouuserdtoBean);
			checkmobileisbindymatouuserdtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, checkmobileisbindymatouuserdtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkmobileisbindymatouuserdtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.USER_YES, checkmobileisbindymatouuserdtoCall.getString("Result"), "验证该手机号绑定过");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckMobileIsBindYmatouUserDto_002() {
		Logger.start(true,"手机未绑定过洋码头账号，验证未绑定过");
		try {
			String phone = TestDataManager.getPhoneNum();
			YmtMobilePhoneAccount user = mobilePhoneWapper.getAccountInfoByPhone(phone);
			if(null!=user){
				phone = TestDataManager.getPhoneNum();
				user = mobilePhoneWapper.getAccountInfoByPhone(phone);
			}
			checkmobileisbindymatouuserdtoBean.setMobile(phone);
			checkmobileisbindymatouuserdtoCall.setData(checkmobileisbindymatouuserdtoBean);
			checkmobileisbindymatouuserdtoCall.callService();			
			Logger.verifyEquals(ECode.SUCCESS, checkmobileisbindymatouuserdtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("true", checkmobileisbindymatouuserdtoCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.USER_NO, checkmobileisbindymatouuserdtoCall.getString("Result"), "验证手机号未绑定过");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_CheckMobileIsBindYmatouUserDto_003() {
		Logger.start(false,"未输入手机号，验证失败");
		try {
			checkmobileisbindymatouuserdtoCall.setData(checkmobileisbindymatouuserdtoBean);
			checkmobileisbindymatouuserdtoCall.callService();			
			Logger.verifyEquals(ECode.ERROR400, checkmobileisbindymatouuserdtoCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("false", checkmobileisbindymatouuserdtoCall.getString("Success"), "验证是否成功");
			Logger.verifyIsContains("错误的", checkmobileisbindymatouuserdtoCall.getString("LastErrorMessage"), "验证Msg信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}